package com.wn.class30.cotroller.houtai;

import com.wn.class30.entity.Franchisees;

import com.wn.class30.service.FranchiseesService;
import com.wn.class30.tools.Page;
import com.wn.class30.tools.Result;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
public class FranchiseesController {
    @Resource
    private FranchiseesService franchiseesService;
    @RequestMapping("/houtai/page/franchisees/list")
    @RequiresPermissions("/houtai/page/franchisees/list")
    public Result getList()throws Exception{
        return new Result("200","success",null,null);
    }
    @RequestMapping("/houtai/franchisees/getFranchisees")
    public Result getFranchiseesByPage(Integer page,Integer limit,String name,String city,String status,String tel) throws Exception{
        Map<String,String> map = new HashMap<>();
        map.put("page",String.valueOf(page));
        map.put("limit",String.valueOf(limit) );
        map.put("name", name);
        map.put("tel", tel);
        map.put("status", status);
        map.put("city", city);
        Page pager = new Page();
        pager.setCurrentPage(page);
        pager.setPageSize(limit);
        int count = franchiseesService.selectCount((HashMap) map);
        pager.setTotalSize(count);
        pager.setTotalPage(count%limit==0?count/limit:count/limit+1);
        return new Result("0","success",pager, (List) franchiseesService.select((HashMap) map));
    }
    @RequestMapping("/houtai/page/franchisees/delete")
    @RequiresPermissions("/houtai/page/franchisees/delete")
    public Result deleteFranchisees(@RequestParam("franchiseesIds[]") Integer[] franchiseesIds)throws Exception{

        for (Integer franchiseesId : franchiseesIds) {
            franchiseesService.deleteById(franchiseesId);
        }

        return new Result("0","success",null, null);
    }
    @RequestMapping("/houtai/page/franchisees/update")
    @RequiresPermissions("/houtai/page/franchisees/update")
    public Result updateFranchisees(Franchisees franchisees)throws Exception{
        franchiseesService.updateFranchisees(franchisees);
        return new Result("0","success",null, null);
    }
    @RequestMapping("/houtai/page/franchisees/insert")
    public Result insertFranchisees(Franchisees franchisees)throws Exception{

        franchiseesService.insertFranchisees(franchisees);
        return new Result("0","success",null, null);
    }
}
